package com.wolf.cx330.view.frag

import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.wolf.cx330.R
import kotlinx.android.synthetic.main.frag_camera_anim.*

class CameraAnimFrag : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.frag_camera_anim, container, false)

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        /*val rotateAnim = ObjectAnimator.ofFloat(pcaCameraAnimView, "canvasRotate", 0F, 360F).apply {
            repeatCount = ObjectAnimator.INFINITE
            repeatMode = ObjectAnimator.RESTART
            duration = 2000
            interpolator = LinearInterpolator()
        }
        val clipAnim = ObjectAnimator.ofFloat(pcaCameraAnimView, "cameraRotateX", 0F, 360F).apply {
            repeatCount = ObjectAnimator.INFINITE
            repeatMode = ObjectAnimator.RESTART
            duration = 100000
            interpolator = AccelerateDecelerateInterpolator()

        }

        AnimatorSet().apply {
            playTogether(rotateAnim,clipAnim)
            startDelay = 1000
            start()
        }*/

        /*val bottomFlipHolder = PropertyValuesHolder.ofFloat("bottomFlip", 45f)
        val topFlipHolder = PropertyValuesHolder.ofFloat("topFlip", 45f)
        val flipRotationHolder =
            PropertyValuesHolder.ofFloat("flipRotation", 270f)
        val animator = ObjectAnimator.ofPropertyValuesHolder(
            pcaCameraAnimView,
            bottomFlipHolder,
            topFlipHolder,
            flipRotationHolder
        )
        animator.duration = 1000
        animator.startDelay = 1000
        animator.start()*/

        /*val cameraRotateXBHolder = PropertyValuesHolder.ofFloat("cameraRotateXB", 45F)
        val canvasRotateHolder = PropertyValuesHolder.ofFloat("canvasRotate", 270F)
        val cameraRotateXTHolder = PropertyValuesHolder.ofFloat("cameraRotateXT", 45F)*/

        val cameraRotateXBAnim =
            ObjectAnimator.ofFloat(pcaCameraAnimView, "cameraRotateXB", 45F).apply {

            }
        val cameraRotateXTAnim =
            ObjectAnimator.ofFloat(pcaCameraAnimView, "cameraRotateXT", -45F).apply {

            }
        val canvasRotateAnim =
            ObjectAnimator.ofFloat(pcaCameraAnimView, "canvasRotate", 270F).apply {

            }

        val set = AnimatorSet().apply {
            playSequentially(cameraRotateXBAnim, canvasRotateAnim, cameraRotateXTAnim)
            duration = 500
            startDelay = 1000
            start()
            addListener(object:Animator.AnimatorListener{
                override fun onAnimationRepeat(animation: Animator?) {
                }

                override fun onAnimationEnd(animation: Animator?) {
                    if (!isRunning) {
                        start()
                    }
                }

                override fun onAnimationCancel(animation: Animator?) {
                }

                override fun onAnimationStart(animation: Animator?) {
                }
            })
        }


    }
}